#ifndef _UTIL_H
#define _UTIL_H

#ifdef __cplusplus
extern "C"
{
#endif
#ifndef M_PI
    #define M_PI (float)3.1415926535
#endif
		
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Abs(a) ((a) >= 0 ? (a) : -(a))
#define RadToDeg(x) ((x)*57.295779513)
#define DegToRad(x) ((x)*0.01745329252)
#define BIT_SET(x, n) ((x) = (x) | (0x01 << n))
#define BIT_CHECK(x, n) (((x) & (0x01 << n)) != 0)
#define BIT_CLEAR(x, n) ((x) = (x) & ~(0x01 << n))


double wrap_angle(double a);
float first_order_filter(float sampling_data, float last_result, float coefficient);
// float sum(float *array, short size);
// float mean(float *array, short size);
// float variance(float *array, short size);
float mean(float last_avg, float new_data, float old_data, short size);
float variance(float last_var, float last_avg, float new_data, float old_data, short size);
void endian_mode_transform_4bytes(unsigned char *input, unsigned char *output);
void endian_mode_transform_2bytes(unsigned char *input, unsigned char *output);
unsigned int hash_fun(unsigned int key);

#ifdef __cplusplus
}
#endif

#endif